#ifndef _BITS_HPP_20120406
#define _BITS_HPP_20120406

#include "base.hpp"

namespace buffer
{
	class ListBuffer;

	namespace bits 
	{
		struct Endian
		{
			public :
				static int32_t endian() { return obj.c; }

				enum { big_endian = 0, little_endian = 1 };

				static const byte * name[]; 

			private :
				union Obj 
				{   
					int16_t s;
					byte  c;  
					Obj() { s = (int16_t)1; }
				};  
				static Obj obj;
		};


		template <typename _T>
			void getB(ListBuffer & buffer, _T & val);

		template <typename _T>
			void getL(ListBuffer & buffer, _T & val);

		template <typename _T>
			void get(ListBuffer & buffer, _T & val)
			{
				(Endian::endian()? getB<_T>(buffer, val): getL<_T>(buffer, val));
			}

		template <typename _T>
			void putB(ListBuffer & buffer, const _T & val);
		
		template <typename _T>
			void putL(ListBuffer & buffer, const _T & val);

		/// base type 
		template <typename _T>
			void put(ListBuffer & buffer, const _T & val)
			{
				if (Endian::endian())
				{
					putB<_T>(buffer, val);
				}
				else
				{
					putL<_T>(buffer, val);
				}
			}
	};
};

#endif

